extends Node2D
class_name MainGame

@onready var loading: Control = $Loading/CanvasLayer/LoadingUI
@onready var sub_scence: Node2D = $SubScence
@onready var progress_bar: ProgressBar = $Loading/CanvasLayer/LoadingUI/ProgressBar

const start_path:String = "res://Scences/start_scence.tscn"

var _loading = true;
var _loading_progress:Array[float] = [0]

func _ready() -> void:
	ResourceLoader.load_threaded_request(start_path)
	pass
	
func _process(delta: float) -> void:
	if _loading :
		if ResourceLoader.load_threaded_get_status(start_path,_loading_progress) == ResourceLoader.THREAD_LOAD_LOADED:
			var ins = (ResourceLoader.load_threaded_get(start_path) as PackedScene).instantiate()
			sub_scence.add_child(ins)
			_loading = false
			var tween = create_tween()
			tween.tween_property(loading,"modulate:a",1,1)
			tween.tween_property(loading,"modulate:a",0,1)
			tween.finished.connect(_loaded_action)			
			pass
		progress_bar.value = _loading_progress[0] * 100
	pass
func _loaded_action():
	loading.visible = false
	pass
